package com.one.group.utils;

import com.one.group.enums.ErrorCode;
import com.one.group.enums.ResultEnum;
import com.one.group.exception.BusinessException;

/**
 * {@code @Create:}  2025-09-28  12 : 37
 * {@code @Author:} Cherry
 * {@code @ToUser:} 凡是发生,皆有利于我。
 * ------------------------------------
 * {@code @note:}
 */

@SuppressWarnings({"all"})
public class ThrowUtil {
    public static <T> void throwIf(Boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    public static <T> void throwIf(Boolean condition, ErrorCode errorCode) {
        if (condition) {
            throw new BusinessException(errorCode);
        }
    }
    public static <T> void throwIf(Boolean condition, ResultEnum resultEnum) {
        if (condition) {
            throw new BusinessException(resultEnum);
        }
    }

    public static <T> void throwIf(Boolean condition, int code, String message) {
        if (condition) {
            throw new BusinessException(code, message);
        }
    }

    public static <T> void throwIf(Boolean condition, ErrorCode errorCode, String message) {
        if (condition) {
            throw new BusinessException(errorCode, message);
        }
    }
    public static <T> void throwIf(Boolean condition, ResultEnum resultEnum, String message) {
        if (condition) {
            throw new BusinessException(resultEnum, message);
        }
    }
}
